<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="https://unpkg.com/nosleep.js@0.12.0/dist/NoSleep.min.js"></script>
  </head>
  <body style="padding-top: 900px">
    <h1></h1>
    <button id="toggle">关闭防熄屏</button>

    <script>
      const noSleep = new NoSleep();
      const toggleBtn = document.getElementById('toggle');
      let isEnabled = true;

      // 默认启用
      noSleep.enable();

      toggleBtn.addEventListener('click', () => {
        if (isEnabled) {
          noSleep.disable();
          toggleBtn.textContent = '开启防熄屏';
        } else {
          noSleep.enable();
          toggleBtn.textContent = '关闭防熄屏';
        }
        isEnabled = !isEnabled;
      });
    </script>
  </body>
</html>
